import express from "express";
import cors from "cors";
import uploadRouter from "./tools/upload/index.js";
import imageRouter from "./tools/image/index.js";
import videoRouter from "./tools/video/index.js";
import ttsRouter from "./tools/tts/index.js";
import pdfRouter from "./tools/pdf/index.js";
import downloadRouter from "./tools/download/index.js";
import messageRouter from "./router/message.js";
import { clearUploadsContentSchedule } from "./utils/schedule.js";

const app = express();

const whiteList = [
  "https://tool.hoshinagi.top",
  "http://tool.hoshinagi.top",
  "http://localhost:5173",
];

const corsOption = {
  origin: whiteList,
  credentials: true,
  allowedHeaders: ["Content-Type", "Authorization", "X-Requested-With"],
  methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
};

app.use(express.json());
app.use(cors(corsOption));
app.use("/upload", uploadRouter);
app.use("/image", imageRouter);
app.use("/video", videoRouter);
app.use("/tts", ttsRouter);
app.use("/pdf", pdfRouter);
app.use("/download", downloadRouter);
app.use("/message", messageRouter);

app.listen(3000, () => {
  console.log("服务启动在3000端口");
  clearUploadsContentSchedule();
  console.log("定时任务已经启动");
});
